import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "Servlet")
//@SuppressWarnings("deprecation")
//@WebServlet(asyncSupported = true)
public class Servlet extends HttpServlet {
    private static final long serialVersionUID = 5522372203700422672L;
    private String message;

    public void init() throws ServletException
    {
        // 执行必需的初始化
        message = "你好啊啊啊";
        System.out.println("初始化servlet");
    }
    protected void doOptions(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Credentials", "true");
        response.setHeader("Access-Control-Allow-Methods", "*");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "Authorization,Origin,X-Requested-With,Content-Type,Accept,"
                + "content-Type,origin,x-requested-with,content-type,accept,authorization,token,id,X-Custom-Header,X-Cookie,Connection,User-Agent,Cookie,*");
        response.setHeader("Access-Control-Request-Headers", "Authorization,Origin, X-Requested-With,content-Type,Accept");
        response.setHeader("Access-Control-Expose-Headers", "*");
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置响应内容类型
        response.setContentType("text/html");
        // 编码问题
        response.setCharacterEncoding("utf-8");
        // 获取响应输出流  是个流
        PrintWriter out = response.getWriter();
        System.out.println("你好");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>123</title>");
        out.println("</head>");

        out.println("<body>");
        out.println("<h1> hello world </h1>");
        out.println("<h1> 你好 </h1>");
//        out.println("<h1>"+this.message+"</h1>");
        out.println("<h1> hello world </h1>");
        out.println("</body>");
        out.println("</html>");




    }


    public void destroy() {
        // servlet终止(销毁)...
        System.out.println("servlet实例销毁了");
    }


 /*    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException{
     service() 方法是执行实际任务的主要方法。
        Servlet 容器（即 Web 服务器）调用 service() 方法来处理来自客户端（浏览器）的请求，并把格式化的响应写回给客户端。
        每次服务器接收到一个 Servlet 请求时，服务器会产生一个新的线程并调用服务。service() 方法检查
        HTTP 请求类型（GET、POST、PUT、DELETE 等），并在适当的时候调用 doGet、doPost、doPut，doDelete 等方法。
        // 您不用对 service() 方法做任何动作，您只需要根据来自客户端的请求类型来重写 doGet() 或 doPost() 即可。


        //这里面什么都不用写
    }*/
}
